﻿using Engine;
using Game;
using Mekiasm.Common;
namespace Mekiasm
{
    public class Robit : ComplexModelItem
    {
        public static int Index;

        public Robit() : base(new ModelItem[] {
            new ModelItem("Bottom", "robit_item"), new ModelItem("Bottom2", "robit_item"), new ModelItem("headback", "robit_item"),
            new ModelItem("lefthand", "robit_item"), new ModelItem("righthand", "robit_item"), new ModelItem("Neck", "robit_item"),
            new ModelItem("Backpack", "robit_item"), new ModelItem("Body", "robit_item"), new ModelItem("backLight", "robit_item"),
            new ModelItem("rightarn", "robit_item"), new ModelItem("LeftTrack", "robit_item"), new ModelItem("RightTrack", "robit_item"),
            new ModelItem("Head", "robit_item"), new ModelItem("leftarm", "robit_item"), new ModelItem("eyeLeft", "robit_item"),
            new ModelItem("eyeRight", "robit_item") }, "robit_n", "机器人")
        {
            
        }

        public override bool OnUse(Ray3 aim, ComponentMiner componentMiner, TerrainRaycastResult? raycast)
        {
            if (raycast.HasValue)
            {
                ComponentBlockEntity blockEntity = ILibrary.SubsystemBlockEntities.GetBlockEntity(raycast.Value.CellFace.X, raycast.Value.CellFace.Y, raycast.Value.CellFace.Z);
                if (blockEntity == null)
                {
                    DisplayMsg(componentMiner.ComponentPlayer,"你需要一个充电桩来放置机器人");
                }
                else
                {
                    ComponentChargepad chargepad = blockEntity.Entity.FindComponent<ComponentChargepad>();
                    if (chargepad == null)
                    {
                        DisplayMsg(componentMiner.ComponentPlayer, "你需要一个充电桩来放置机器人");
                    }
                    else
                    {
                        ILibrary.AddAnimalEntity("Robit", raycast.Value.CellFace.X, raycast.Value.CellFace.Y, raycast.Value.CellFace.Z);
                    }
                }
            }
            return true;
        }

    }
}
